//
//  InventoryManageViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-6-8.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "InventoryManageViewController.h"
#import "InventoryManageTableViewCell.h"
#import "GuideListTableViewCell.h"
#import "InventoryInputTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "EGORefreshTableHeaderView.h"
#import "SearchProductTableViewCell.h"
//#import "UpCounterDetailTableViewCell.h"
#import "InventoryDetailTableViewCell.h"
#import "CommonScanViewController.h"
#import "FilterViewController.h"
#import "CommonProductDetailViewController.h"
@interface InventoryManageViewController ()<InventoryManageTableViewCellDelegate,EGORefreshTableHeaderDelegate,CommonScanDelegate,FilterViewControllerDelegate,CommonProductDetailDelegate>
{
    FilterViewController *filterVC;
    CommonScanViewController *commonScanVC;
    CommonProductDetailViewController *commonProductDetailVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;
    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;
    
    NSUInteger _detailPageIndex;
    NSUInteger _detailTotalCount;
    NSUInteger _detailTotalPage;
    
    NSMutableArray *inventoryNumArray;
    NSMutableArray *inventoryNumberArray;
    NSMutableArray *inventoryStatusArray;
    NSMutableArray *inventoryWeightArray;
    NSMutableArray *inventoryPriceArray;
    NSMutableArray *inventoryDateArray;
    NSMutableArray *inventoryGuideNameArray;
    NSMutableArray *inventoryProductNameArray;
    
    BOOL guideIsOpen;
    BOOL styleIsOpen;
    BOOL wareHouseIsOpen;
    NSString *guideCodeStr;
    NSString *styleCodeStr;
    NSString *wareHouseCodeStr;
    
    NSMutableArray *guideCodeArray;
    NSMutableArray *guideNameArray;
    NSMutableArray *styleCodeArray;
    NSMutableArray *styleNameArray;
    NSMutableArray *wareHouseCodeArray;
    NSMutableArray *wareHouseNameArray;
    
    NSMutableArray *inventoryInputUrlArray;
    NSMutableArray *inventoryInputProductNameArray;
    NSMutableArray *inventoryInputAddressArray;
    NSMutableArray *inventoryInputWeightArray;
    NSMutableArray *inventoryInputPriceArray;
    NSMutableArray *inventoryInputCodeArray;
    
    NSString *inventoryTypeStr;
    NSString *inventoryNumStr;
    NSMutableArray *detailCodeArray;
    NSMutableArray *detailUrlArray;
    NSMutableArray *detailProductNameArray;
    NSMutableArray *detailAddressArray;
    NSMutableArray *detailWeightArray;
    NSMutableArray *detailAttributesArray;
    NSMutableArray *detailPriceArray;
    NSMutableArray *detailGuideNameArray;
    
    
    NSString *IQtyStr;
    NSString *IGramStr;
    
    NSString *YQtyStr;
    NSString *YGramStr;
    
    NSString *KQtyStr;
    NSString *KGramStr;
    
    NSInteger inventoryCellTag;
    
    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;
    
    
    NSUInteger searchProductCellTag;
    UITextField *inputTextField;
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

    NSString *continueItemCodeStr;
    
  }
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end

@implementation InventoryManageViewController
-(void)viewWillAppear:(BOOL)animated
{
     if ([_isLoad isEqualToString:@"N"]) {
    if (commonProductDetailVC.view!=nil) {
             
             [commonProductDetailVC removeFromParentViewController];
             [commonProductDetailVC.view removeFromSuperview];
             
         }

    if (commonScanVC.view!=nil) {
        if (commonScanVC.timer!=nil) {
            [commonScanVC.timer invalidate];
            commonScanVC.timer=nil;
        }
        if (commonScanVC.captureSession!=nil) {
            
            
            [commonScanVC.captureSession stopRunning];
            commonScanVC.captureSession = nil;
        }
        if (commonScanVC.videoPreviewLayer !=nil) {
            
            
            [commonScanVC.videoPreviewLayer removeFromSuperlayer];
        }

        [commonScanVC.view removeFromSuperview];
        [commonScanVC removeFromParentViewController];
        
    }
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }

    [self initInventoryList];
    [self initInventoryInput];
    [self initInventoryDetail];
  //  [self initSearchViewContainer];
    [self initOrderFilterView];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
     }

}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"DCheckVouch";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [inventoryNumArray removeAllObjects];
    [inventoryProductNameArray removeAllObjects];
    [inventoryGuideNameArray removeAllObjects];
    [inventoryDateArray removeAllObjects];
    [inventoryStatusArray removeAllObjects];
    [inventoryPriceArray removeAllObjects];
    [inventoryNumberArray removeAllObjects];
    [inventoryWeightArray removeAllObjects];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
}

-(void)initInventoryList
{
    _searchTextField.text=@"";
    inventoryNumArray=[NSMutableArray array];
    inventoryStatusArray=[NSMutableArray array];
    inventoryWeightArray=[NSMutableArray array];
    inventoryNumberArray=[NSMutableArray array];
    inventoryPriceArray=[NSMutableArray array];
    inventoryDateArray=[NSMutableArray array];
    inventoryProductNameArray=[NSMutableArray array];
    inventoryGuideNameArray=[NSMutableArray array];
    styleCodeArray=[NSMutableArray array];
    styleNameArray=[NSMutableArray array];
}
-(void)initInventoryDetail
{
    IQtyStr=@"";
    IGramStr=@"";
    
    YQtyStr=@"";
    YGramStr=@"";
    
    KQtyStr=@"";
    KGramStr=@"";
    

    detailUrlArray=[NSMutableArray array];
    detailProductNameArray=[NSMutableArray array];
    detailAddressArray=[NSMutableArray array];
    detailWeightArray=[NSMutableArray array];
    detailGuideNameArray=[NSMutableArray array];
    detailAttributesArray=[NSMutableArray array];
    detailPriceArray=[NSMutableArray array];
    detailCodeArray=[NSMutableArray array];
    //detailCodeArray=[NSMutableArray array];
    [_inventoryConfirmBtn setBackgroundColor:[UIColor colorWithRed:199.0f/255.0f green:156.0f/255.0f blue:44.0f/255.0f alpha:1.0f]];
     [_inventoryConfirmBtn setUserInteractionEnabled:YES];
    inventoryTypeStr=@"";
    [_panYinBtn addTarget:self action:@selector(panYinBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_panKuiBtn addTarget:self action:@selector(panKuiBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_panCunBtn addTarget:self action:@selector(panCunBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _panKuiLine.hidden=YES;
    _panCunLine.hidden=YES;
    _panYinLine.hidden=NO;
    
    CGRect viewFrame=_detailViewContainer.frame;
    viewFrame.origin.y=768;
    _detailViewContainer.frame=viewFrame;
    [_detailAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_detailAlphaView addTarget:self action:@selector(detailAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];

    continueItemCodeStr=@"";
}
-(void)panYinBtnClick
{
    inventoryTypeStr=@"Y";
    _panCunLine.hidden=YES;
    _panKuiLine.hidden=YES;
    _panYinLine.hidden=NO;
    [detailUrlArray removeAllObjects];
    [detailProductNameArray removeAllObjects];
    [detailAddressArray removeAllObjects];
    [detailWeightArray removeAllObjects];
    [detailGuideNameArray removeAllObjects];
    [detailAttributesArray removeAllObjects];
    [detailPriceArray removeAllObjects];
    [detailCodeArray removeAllObjects];
    //[detailCodeArray removeAllObjects];
    _detailTotalCountLabel.text=[NSString stringWithFormat:@"(共有%@件,%@g)",YQtyStr,YGramStr];
  //  [self resizeLabel:_detailTotalCountLabel];
    [Global resizeForLable:_detailTotalCountLabel WithText:_detailTotalCountLabel.text parentView:self.view];
    _detailPageIndex=0;
    [self loadDetailNextPage:_detailPageIndex];

}
-(void)panKuiBtnClick
{
    inventoryTypeStr=@"K";
    _panCunLine.hidden=YES;
    _panKuiLine.hidden=NO;
    _panYinLine.hidden=YES;
    [detailUrlArray removeAllObjects];
    [detailProductNameArray removeAllObjects];
    [detailAddressArray removeAllObjects];
    [detailWeightArray removeAllObjects];
    [detailGuideNameArray removeAllObjects];
    [detailAttributesArray removeAllObjects];
    [detailPriceArray removeAllObjects];
    [detailCodeArray removeAllObjects];
    //[detailCodeArray removeAllObjects];
    _detailTotalCountLabel.text=[NSString stringWithFormat:@"(共有%@件,%@g)",KQtyStr,KGramStr];
    // [self resizeLabel:_detailTotalCountLabel];
     [Global resizeForLable:_detailTotalCountLabel WithText:_detailTotalCountLabel.text parentView:self.view];
    _detailPageIndex=0;
    [self loadDetailNextPage:_detailPageIndex];

}
-(void)panCunBtnClick
{
    inventoryTypeStr=@"I";
    _panCunLine.hidden=NO;
    _panKuiLine.hidden=YES;
    _panYinLine.hidden=YES;
    [detailUrlArray removeAllObjects];
    [detailProductNameArray removeAllObjects];
    [detailAddressArray removeAllObjects];
    [detailWeightArray removeAllObjects];
    [detailGuideNameArray removeAllObjects];
    [detailAttributesArray removeAllObjects];
    [detailPriceArray removeAllObjects];
    [detailCodeArray removeAllObjects];
   // [detailCodeArray removeAllObjects];
     _detailTotalCountLabel.text=[NSString stringWithFormat:@"(共有%@件,%@g)",IQtyStr,IGramStr];
    // [self resizeLabel:_detailTotalCountLabel];
    [Global resizeForLable:_detailTotalCountLabel WithText:_detailTotalCountLabel.text parentView:self.view];
    _detailPageIndex=0;
    [self loadDetailNextPage:_detailPageIndex];

}
-(void)initInventoryInput
{
    
   guideCodeStr=@"";
   styleCodeStr=@"";
   wareHouseCodeStr=@"";
   guideCodeArray=[NSMutableArray array];
   guideNameArray=[NSMutableArray array];
   wareHouseCodeArray=[NSMutableArray array];
    wareHouseNameArray=[NSMutableArray array];
    
   inventoryInputUrlArray=[NSMutableArray array];
   inventoryInputProductNameArray=[NSMutableArray array];
   inventoryInputAddressArray=[NSMutableArray array];
   inventoryInputWeightArray=[NSMutableArray array];
   inventoryInputPriceArray=[NSMutableArray array];
   inventoryInputCodeArray=[NSMutableArray array];
     guideIsOpen=NO;
     styleIsOpen=NO;
     wareHouseIsOpen=NO;
     [_selectGuideBtn addTarget:self action:@selector(selectGuideBtnClick) forControlEvents:UIControlEventTouchUpInside];
     [_selectStyleBtn addTarget:self action:@selector(selectStyleBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_selectWareHouseBtn addTarget:self action:@selector(selectWareHouseBtnClick) forControlEvents:UIControlEventTouchUpInside];
    CGRect viewFrame=_inventoryInputViewContainer.frame;
    viewFrame.origin.y=768;
    _inventoryInputViewContainer.frame=viewFrame;
    [_inventoryInputAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_inventoryInputAlphaView addTarget:self action:@selector(inventoryInputAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    _guideListViewContainer.hidden=YES;
    CGRect frame=_guideListViewContainer.frame;
    frame.size.height=1;
    [_guideListViewContainer setFrame:frame];
    
    _styleListView.hidden=YES;
    CGRect frame1=_styleListView.frame;
    frame1.size.height=1;
    [_styleListView setFrame:frame1];
    
    _wareHouseListView.hidden=YES;
    CGRect frame2=_wareHouseListView.frame;
    frame2.size.height=1;
    [_wareHouseListView setFrame:frame2];

}
-(void)inventoryInputAlphaViewClick
{
     if (_selectWareHouseBtn.userInteractionEnabled)
     {
    [_searchTextField resignFirstResponder];
  //  [_inputSearchTextField resignFirstResponder];
    [_searchProductTextField resignFirstResponder];
    if (inventoryInputUrlArray.count>0) {
        [inventoryNumArray removeAllObjects];
        [inventoryProductNameArray removeAllObjects];
        [inventoryGuideNameArray removeAllObjects];
        [inventoryDateArray removeAllObjects];
        [inventoryStatusArray removeAllObjects];
        [inventoryWeightArray removeAllObjects];
        [inventoryPriceArray removeAllObjects];
        [inventoryNumberArray removeAllObjects];
        
    
        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];

    }
    }
   else{
        
        [detailUrlArray removeAllObjects];
        [detailProductNameArray removeAllObjects];
        [detailAddressArray removeAllObjects];
        [detailWeightArray removeAllObjects];
       [detailGuideNameArray removeAllObjects];
        [detailAttributesArray removeAllObjects];
        [detailPriceArray removeAllObjects];
        [detailCodeArray removeAllObjects];
        // [detailCodeArray removeAllObjects];
       
        inventoryTypeStr=@"Y";
        _panCunLine.hidden=YES;
        _panKuiLine.hidden=YES;
        _panYinLine.hidden=NO;
        [_inventoryConfirmBtn setBackgroundColor:[UIColor colorWithRed:199.0f/255.0f green:156.0f/255.0f blue:44.0f/255.0f alpha:1.0f]];
        [_inventoryConfirmBtn setUserInteractionEnabled:YES];
        
        
        [self requestDetailHead];
        _detailPageIndex=0;
        [self loadDetailNextPage:_detailPageIndex];
    }
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_inventoryInputViewContainer.frame;
         viewFrame.origin.y=768;
         _inventoryInputViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
-(void)detailAlphaViewClick
{
    [_searchTextField resignFirstResponder];
//[_inputSearchTextField resignFirstResponder];
    [_searchProductTextField resignFirstResponder];
    
    [_detailScrollview setContentOffset:CGPointMake(0, 0)];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_detailViewContainer.frame;
         viewFrame.origin.y=768;
         _detailViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
-(void)selectGuideBtnClick
{
    UIImage *image=[UIImage imageNamed:@"jiantou_down.png"];
    [_selectStyleArrow setImage:image];
    [_selectWareHouseArrow setImage:image];
    _styleListView.hidden=YES;
    CGRect frame1=_styleListView.frame;
    frame1.size.height=1;
    [_styleListView setFrame:frame1];
    
    _wareHouseListView.hidden=YES;
    CGRect frame2=_styleListView.frame;
    frame2.size.height=1;
    [_wareHouseListView setFrame:frame2];
    if (guideIsOpen) {
        _guideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_selectGuideArrow setImage:closeImage];
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=1;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            guideIsOpen=NO;
        }];
        
    }
    else
    {
        [self requestGuideList];
        _guideListViewContainer.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
            
            
            [_selectGuideArrow setImage:closeImage];
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=657;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            guideIsOpen=YES;
        }];
        
    }
    

}
-(void)requestGuideList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [HttpRequest requestData:@"Guide/GuideList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [guideCodeArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                    NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [guideCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserCode"]];
                        [guideNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"UserName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_guideListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(IBAction)inventoryConfirmClick:(id)sender
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:_detailNumLabel.text forKey:@"DocNum"];
        [HttpRequest requestData:@"StoreManager/ConfirmCheckVouchDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                  //  _detailStatusLabel.text=@"已确定";
                    [UIView animateWithDuration:0.5f animations:^
                     {
                         CGRect viewFrame=_detailViewContainer.frame;
                         viewFrame.origin.y=768;
                         _detailViewContainer.frame=viewFrame;
                     }completion:^(BOOL finished) {
                         
                     }];

                    [inventoryNumArray removeAllObjects];
                    [inventoryProductNameArray removeAllObjects];
                    [inventoryGuideNameArray removeAllObjects];
                    [inventoryDateArray removeAllObjects];
                    [inventoryStatusArray removeAllObjects];
                    [inventoryWeightArray removeAllObjects];
                    [inventoryNumberArray removeAllObjects];
                    [inventoryPriceArray removeAllObjects];
                    _productPageIndex=0;
                    [self loadProductNextPage:_productPageIndex];
                    
//                    NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:inventoryCellTag inSection:0];
//                    UITableViewCell *cell = [_inventoryListTablebView cellForRowAtIndexPath:indexPath1];
//                    InventoryManageTableViewCell *accountCenterCell=( InventoryManageTableViewCell *)cell;
//                    accountCenterCell.statusLabel.text=@"已确定";
//                    
//                   [accountCenterCell.statusLabel setBackgroundColor:[UIColor colorWithRed:112.0f/255.0f green:177.0f/255.0f blue:36.0f/255.0f alpha:1.0f]];
                    _detailStatusLabel.text=@"已确定";
//                    if ([_detailStatusLabel.text isEqualToString:@"未确定"]) {
//                        //  NSLog(@"statusStr===%@",statusStr);
//                        [_detailStatusLabel setBackgroundColor:[UIColor redColor]];
//                        
//                    }
                    
                    //            if ([statusStr isEqualToString:@"部分到货"]) {
                    //                [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:199.0f/255.0f green:156.0f/255.0f blue:43.0f/255.0f alpha:1.0f]];
                    //            }
                   // else {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:_detailStatusLabel.text]];
                  //  }

                     [_inventoryConfirmBtn setBackgroundColor:[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1.0f]];
                    [_inventoryConfirmBtn setUserInteractionEnabled:NO];
                                   }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)selectStyleBtnClick
{
    
    UIImage *image=[UIImage imageNamed:@"jiantou_down.png"];
    [_selectGuideArrow setImage:image];
    [_selectWareHouseArrow setImage:image];
    _guideListViewContainer.hidden=YES;
    CGRect frame1=_guideListViewContainer.frame;
    frame1.size.height=1;
    [_guideListViewContainer setFrame:frame1];
    
    _wareHouseListView.hidden=YES;
    CGRect frame2=_styleListView.frame;
    frame2.size.height=1;
    [_wareHouseListView setFrame:frame2];

    if (styleIsOpen) {
      
        _styleListView.hidden=YES;
        
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_selectStyleArrow setImage:closeImage];
            CGRect frame=_styleListView.frame;
            
            frame.size.height=1;
            [_styleListView setFrame:frame];
            
        } completion:^(BOOL finished){
            styleIsOpen=NO;
        }];
        
    }
    else
    {
         [self requestStyleList];
              _styleListView.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
            
            
            [_selectStyleArrow setImage:closeImage];
            
            //[_selectGuideArrowImageView setImage:closeImage];
            CGRect frame=_styleListView.frame;
            
            frame.size.height=603;
            [_styleListView setFrame:frame];
            
        } completion:^(BOOL finished){
            styleIsOpen=YES;
        }];
        
    }

}
-(void)requestStyleList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"CheckVouch" forKey:@"BType"];
        [HttpRequest requestData:@"StoreManager/GetMItypeList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [styleCodeArray removeAllObjects];
                    [styleNameArray removeAllObjects];
                   // NSLog(@"3333=%@",severDataDict.dataDict);
                    NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [styleCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"ItypeCode"]];
                        [styleNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"ItypeName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_styleListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                                [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

-(void)selectWareHouseBtnClick
{
     UIImage *img=[UIImage imageNamed:@"jiantou_down.png"];
    [_selectStyleArrow setImage:img];
    [_selectGuideArrow setImage:img];
    _guideListViewContainer.hidden=YES;
    CGRect frame1=_guideListViewContainer.frame;
    frame1.size.height=1;
    [_guideListViewContainer setFrame:frame1];
    
    _styleListView.hidden=YES;
    CGRect frame2=_styleListView.frame;
    frame2.size.height=1;
    [_styleListView setFrame:frame2];

    if (wareHouseIsOpen) {
        _wareHouseListView.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_selectWareHouseArrow setImage:closeImage];
            CGRect frame=_wareHouseListView.frame;
            
            frame.size.height=1;
            [_wareHouseListView setFrame:frame];
            
        } completion:^(BOOL finished){
            wareHouseIsOpen=NO;
        }];
        
    }
    else
    {
        [self requestWareHouseList];
        _wareHouseListView.hidden=NO;
        [UIView animateWithDuration:0.5 animations:^{
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_upward.png"];
            
            
            [_selectWareHouseArrow setImage:closeImage];
            CGRect frame=_wareHouseListView.frame;
            frame.origin.y=217;
            frame.size.height=551;
            [_wareHouseListView setFrame:frame];
            
        } completion:^(BOOL finished){
            wareHouseIsOpen=YES;
        }];
        
    }


}
-(void)requestWareHouseList
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"C" forKey:@"WhsType"];
       //  NSLog(@"params===%@",params);
        [HttpRequest requestData:@"StoreManager/WhsList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
           
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    [wareHouseCodeArray removeAllObjects];
                    [wareHouseNameArray removeAllObjects];
                    // NSLog(@"3333=%@",severDataDict.dataDict);
                    NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    for (int i=0; i<mGuidesArray.count; i++) {
                        [wareHouseCodeArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"WhsCode"]];
                        [wareHouseNameArray addObject:[[mGuidesArray objectAtIndex:i] objectForKey:@"WhsName"]];
                    }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_wareHouseListTableView reloadData];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                    [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(IBAction)continueInventoryBtnClick:(id)sender
{
    _inventoryNumLabel.text=@"";
    [_searchTextField resignFirstResponder];
    UIImage *image=[UIImage imageNamed:@"jiantou_down.png"];
    [_selectStyleArrow setImage:image];
    [_selectWareHouseArrow setImage:image];
    [_selectGuideArrow setImage:image];
    [inventoryInputUrlArray removeAllObjects];
    [inventoryInputProductNameArray removeAllObjects];
    [inventoryInputAddressArray removeAllObjects];
    [inventoryInputWeightArray removeAllObjects];
    [inventoryInputPriceArray removeAllObjects];
    [inventoryInputCodeArray removeAllObjects];
    [_inventoryInputTableView reloadData];
   
    _inventoryInputTotalLabel.text=@"(共0件，0.00g)";
    _selectGuideLabel.text=[Global getGuideNameStr];
    guideCodeStr=[Global getGuideCodeStr];
    [Global resizeForLable:_selectGuideLabel WithText:_selectGuideLabel.text parentView:self.view];
    CGRect frameK=_selectGuideLabel.frame;
    frameK.origin.x=_selectGuideArrow.frame.origin.x-frameK.size.width-5;
    _selectGuideLabel.frame=frameK;
    
    [_selectWareHouseBtn setUserInteractionEnabled:NO];
    [_selectStyleBtn setUserInteractionEnabled:NO];
    _selectWareHouseArrow.hidden=YES;
    _selectStyleArrow.hidden=YES;
    
    continueItemCodeStr=_detailNumLabel.text;
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_inventoryInputViewContainer.frame;
         viewFrame.origin.y=0;
         _inventoryInputViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];
    [self  requestInventoryNum];

}
-(IBAction)inventoryInputBtnClick:(id)sender
{
    _searchProductTextField.text=@"";
     _inventoryNumLabel.text=@"";
    _inventoryInputNoteView.hidden=YES;
    CGRect frameQ=_inventoryInputInfoView.frame;
    frameQ.origin.y=_inputReferLineLabel.frame.origin.y+_inputReferLineLabel.frame.size.height+1;
    _inventoryInputInfoView.frame=frameQ;
    
    CGRect frameW=_inventoryInputTableView.frame;
    frameW.origin.y=_inventoryInputInfoView.frame.origin.y+_inventoryInputInfoView.frame.size.height+1;
    _inventoryInputTableView.frame=frameW;
     [_searchTextField resignFirstResponder];
    UIImage *image=[UIImage imageNamed:@"jiantou_down.png"];
    [_selectStyleArrow setImage:image];
    [_selectWareHouseArrow setImage:image];
    [_selectGuideArrow setImage:image];
    [inventoryInputUrlArray removeAllObjects];
    [inventoryInputProductNameArray removeAllObjects];
    [inventoryInputAddressArray removeAllObjects];
    [inventoryInputWeightArray removeAllObjects];
    [inventoryInputPriceArray removeAllObjects];
    [inventoryInputCodeArray removeAllObjects];
    [_inventoryInputTableView reloadData];
    _selectWareHouseLabel.text=@"";
     _selectStyleLabel.text=@"";
    _inventoryInputTotalLabel.text=@"(共0件，0.00g)";
    _selectGuideLabel.text=[Global getGuideNameStr];
    [Global resizeForLable:_selectGuideLabel WithText:_selectGuideLabel.text parentView:self.view];
    CGRect frameK=_selectGuideLabel.frame;
    frameK.origin.x=_selectGuideArrow.frame.origin.x-frameK.size.width-5;
    _selectGuideLabel.frame=frameK;
    guideCodeStr=[Global getGuideCodeStr];
    styleCodeStr=@"";
    wareHouseCodeStr=@"";
    continueItemCodeStr=@"";
    
    [_selectWareHouseBtn setUserInteractionEnabled:YES];
    [_selectStyleBtn setUserInteractionEnabled:YES];
    _selectWareHouseArrow.hidden=NO;
    _selectStyleArrow.hidden=NO;

    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_inventoryInputViewContainer.frame;
         viewFrame.origin.y=0;
         _inventoryInputViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
-(void) loadProductNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _productTotalCount<=inventoryNumArray.count)
        return;
    if(oldPageNum == 0){
        [inventoryNumArray removeAllObjects];
        [_inventoryListTablebView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    [self requestInventoryList: _productPageIndex pageSize:6];
}
-(void) loadDetailNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _detailTotalCount<=detailCodeArray.count)
        return;
    if(oldPageNum == 0){
        [detailCodeArray removeAllObjects];
        [_detailTableView reloadData];
    }
    _detailPageIndex=oldPageNum+1;
    [self requestDetailList: _detailPageIndex pageSize:6];
}

-(void)requestInventoryList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            //    NSLog(@"codeContentssss==%@",codeContent);
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            //  NSLog(@"countContentssss==%@",countContent);
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }

        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/CheckVouchList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                  //  NSLog(@"111111222===%@",severDataDict.dataDict);
                   
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _inventoryTotalCount.text=[NSString stringWithFormat:@"共%lu条记录",(unsigned long)_productTotalCount];
                    
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                    NSMutableArray  *inventoryListArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    //   int total=0;
                    if ( inventoryListArray.count>0) {
                        for (int i=0; i< inventoryListArray.count; i++) {
                            [inventoryNumArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [inventoryProductNameArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [inventoryGuideNameArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [inventoryDateArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            [inventoryStatusArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [inventoryWeightArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                            [inventoryNumberArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"Number"]];
                            [inventoryPriceArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            
                        }
                    }

                    [_inventoryListTablebView reloadData];
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                    [Global loginViewController:self noteStr:requestResultStr];
                        //[Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}
-(void)requestDetailHead
{
    
    if ([Global getLoginToken].length>0) {
       // [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
       [params setObject:inventoryNumStr forKey:@"DocNum"];
       
        [HttpRequest requestData:@"StoreManager/GetCheckVouchHead" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                 //   [Global hideProgressHUDInternal:self.view];
                    //_detailTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                  //  NSLog(@"headdddd===%@",severDataDict.dataDict);
                    YQtyStr=[NSString stringWithFormat:@"%ld",(long)[[severDataDict.dataDict objectForKey:@"YQty"] integerValue]];
                    YGramStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"YGram"] floatValue]];
                    
                    KQtyStr=[NSString stringWithFormat:@"%ld",(long)[[severDataDict.dataDict objectForKey:@"KQty"] integerValue]];
                    KGramStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"KGram"] floatValue]];
                    
                    IQtyStr=[NSString stringWithFormat:@"%ld",(long)[[severDataDict.dataDict objectForKey:@"IQty"] integerValue]];
                    IGramStr=[NSString stringWithFormat:@"%0.02f",[[severDataDict.dataDict objectForKey:@"IGram"] floatValue]];
                    
                  
                     _detailTotalCountLabel.text=[NSString stringWithFormat:@"(共有%@件,%@g)",YQtyStr,YGramStr];
                   // [self resizeLabel:_detailTotalCountLabel];
                    
                    [Global resizeForLable:_detailTotalCountLabel WithText:_detailTotalCountLabel.text parentView:self.view];
                    
                    NSString *panYinStr=[NSString stringWithFormat:@"盘盈%ld件",(long)[[severDataDict.dataDict objectForKey:@"YQty"] integerValue]];
                    [_panYinTitle setText:panYinStr];
                    
                    NSString *panKuiStr=[NSString stringWithFormat:@"盘亏%ld件",(long)[[severDataDict.dataDict objectForKey:@"KQty"] integerValue]];
                    [_panKuiTitle setText:panKuiStr];
                    
                    
                    NSString *panCunStr=[NSString stringWithFormat:@"盘存%ld件",(long)[[severDataDict.dataDict objectForKey:@"IQty"] integerValue]];
                    [_panCunTitle setText:panCunStr];
                    
                    _detailNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                   // [self resizeLabel:_detailNumLabel];
                     [Global resizeForLable:_detailNumLabel WithText:_detailNumLabel.text parentView:self.view];
                
                    CGRect frame=_detailStatusLabel.frame;
                    frame.origin.x=_detailNumLabel.frame.origin.x+_detailNumLabel.frame.size.width-5;
                    _detailStatusLabel.frame=frame;
                    
                    _detailHouseNameLabel.text=[severDataDict.dataDict objectForKey:@"WhsName"];
//                    [self resizeLabel:_detailHouseNameLabel];
                     [Global resizeForLable:_detailHouseNameLabel WithText:_detailHouseNameLabel.text parentView:self.view];
                    _detailGuideNameLabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                  //  [self resizeLabel:_detailGuideNameLabel];
                     [Global resizeForLable:_detailGuideNameLabel WithText:_detailGuideNameLabel.text parentView:self.view];
//                    CGRect frame1=_detailDateTagLabel.frame;
//                    frame1.origin.x=_detailGuideNameLabel.frame.origin.x+_detailGuideNameLabel.frame.size.width+15;
//                    _detailDateTagLabel.frame=frame1;
                    
//                    CGRect frame2=_detailDateLabel.frame;
//                    frame2.origin.x=_detailDateTagLabel.frame.origin.x+_detailDateTagLabel.frame.size.width+3;
//                    _detailDateLabel.frame=frame2;
                    wareHouseCodeStr=[severDataDict.dataDict objectForKey:@"WhsCode"];
                    styleCodeStr=[severDataDict.dataDict objectForKey:@"ITypeCode"];
                    _selectWareHouseLabel.text=[severDataDict.dataDict objectForKey:@"WhsName"];
                    [Global resizeForLable:_selectWareHouseLabel WithText:_selectWareHouseLabel.text parentView:self.view];
                    CGRect frameK=_selectWareHouseLabel.frame;
                    frameK.origin.x=_selectWareHouseArrow.frame.origin.x-frameK.size.width-5;
                    _selectWareHouseLabel.frame=frameK;
                    
                    _selectStyleLabel.text=[severDataDict.dataDict objectForKey:@"ITypeName"];
                    [Global resizeForLable:_selectStyleLabel WithText:_selectStyleLabel.text parentView:self.view];
                    CGRect frames=_selectStyleLabel.frame;
                    frames.origin.x=_selectStyleArrow.frame.origin.x-frames.size.width-5;
                    _selectStyleLabel.frame=frames;

                    _detailDateLabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                    
                    NSString *statusStr=[severDataDict.dataDict objectForKey:@"DocStatus"];
                    
                    _detailStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                 //   _detailStatusLabel.text=[inventoryStatusArray objectAtIndex:inventoryCellTag];////[severDataDict.dataDict objectForKey:@"DocStatus"];
                    if ([statusStr isEqualToString:@"未确定"]) {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                        _continueInventoryBtn.hidden=NO;
                        
                    }
                    else {
                        [_detailStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                        _continueInventoryBtn.hidden=YES;
                    }

                    _detailStyleLabel.text=[severDataDict.dataDict objectForKey:@"ITypeName"];
                 //   [self resizeLabel:_detailStyleLabel];
                    [Global resizeForLable:_detailStyleLabel WithText:_detailStyleLabel.text parentView:self.view];
                    
                    CGRect frame3=_detailHouseTagLabel.frame;
                    frame3.origin.x=_detailStyleLabel.frame.origin.x+_detailStyleLabel.frame.size.width+15;
                    _detailHouseTagLabel.frame=frame3;
                    
                    CGRect frame4=_detailHouseNameLabel.frame;
                    frame4.origin.x=_detailHouseTagLabel.frame.origin.x+_detailHouseTagLabel.frame.size.width+3;
                    _detailHouseNameLabel.frame=frame4;
                    
                    CGRect frame5=_detailGuideTagLabel.frame;
                    frame5.origin.x=_detailHouseNameLabel.frame.origin.x+_detailHouseNameLabel.frame.size.width+10;
                    _detailGuideTagLabel.frame=frame5;
                    
                    CGRect frame6=_detailGuideNameLabel.frame;
                    frame6.origin.x=_detailGuideTagLabel.frame.origin.x+_detailGuideTagLabel.frame.size.width+3;
                    _detailGuideNameLabel.frame=frame6;


                    if ([statusStr isEqualToString:@"未确定"]) {
                        [_inventoryConfirmBtn setBackgroundColor:[UIColor colorWithRed:199.0f/255.0f green:156.0f/255.0f blue:44.0f/255.0f alpha:1.0f]];
                        [_inventoryConfirmBtn setUserInteractionEnabled:YES];
                    }
                    else
                    {
                        [_inventoryConfirmBtn setBackgroundColor:[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1.0f]];
                        [_inventoryConfirmBtn setUserInteractionEnabled:NO];
                        
                    }

                }
                else
                {
                   // [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                       
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)requestDetailList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:inventoryNumStr forKey:@"DocNum"];
        [params setObject:inventoryTypeStr forKey:@"KeyWord"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/GetCheckVouchDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   // NSLog(@"pan===%@",severDataDict.dataDict);
                    _detailTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                   
                    if (_detailTotalCount%6!=0) {
                        _detailTotalPage=_detailTotalCount/6+1;
                    }
                    else if (_detailTotalCount%6==0)
                    {
                        _detailTotalPage=_detailTotalCount/6;
                    }
                    
                    NSMutableArray  *inventoryListArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    //   int total=0;
                    if ( inventoryListArray.count>0) {
                        for (int i=0; i< inventoryListArray.count; i++) {
                            [detailUrlArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                            [detailProductNameArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [detailPriceArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"Price"]];
                            [detailCodeArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"ItemCode"]];
                            [detailWeightArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"Gram"]];
                            [detailGuideNameArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"GuideName"] ];
                            [detailAttributesArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"Attributes"]];
                            [detailAddressArray addObject:[[inventoryListArray objectAtIndex:i] objectForKey:@"WhsName"]];
                            
                            
                        }
                    }

                  //  NSLog(@"detailcode===%@",detailCodeArray);
                    [_detailTableView reloadData];
                    //if (_detailTableView.frame.size.height<436) {
//                        CGRect frame1=_detailTableView.frame;
//                        frame1.size.height=120*detailCodeArray.count;
//                        _detailTableView.frame=frame1;
//                    //}
//                    if (_detailTableView.frame.origin.y+_detailTableView.frame.size.height>710) {
//                        CGRect frame2=_inventoryConfirmBtn.frame;
//                        frame2.origin.y=_detailTableView.frame.origin.y+_detailTableView.frame.size.height+20;
//                        _inventoryConfirmBtn.frame=frame2;
//                    }
//                    else
//                    {
//                        CGRect frame2=_inventoryConfirmBtn.frame;
//                        frame2.origin.y=718;
//                        _inventoryConfirmBtn.frame=frame2;
//                    }
//                    [_detailScrollview setContentSize:CGSizeMake(0, _inventoryConfirmBtn.frame.origin.y+ _inventoryConfirmBtn.frame.size.height+10)];
//                    [_detailScrollview setScrollEnabled:YES];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

-(IBAction)addScanClick:(id)sender
{
    if (guideCodeStr.length>0&&styleCodeStr.length>0&&wareHouseCodeStr.length>0) {
        [_addScanBtn setUserInteractionEnabled:YES];
        [_searchProductTextField resignFirstResponder];
        if (commonScanVC.view!=nil) {
            
            [commonScanVC removeFromParentViewController];
            [commonScanVC.view removeFromSuperview];
            
        }
        commonScanVC=[[CommonScanViewController alloc] init];
        commonScanVC.delegate=self;
        
        commonScanVC.view.frame = CGRectMake(0,
                                             0,
                                             self.view.bounds.size.width,
                                             self.view.bounds.size.height);
        
        [self addChildViewController:commonScanVC];
        [self.view addSubview:commonScanVC.view];

       
    }

   else
   {
      
           UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择导购、类别、仓库" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
           [alert show];
       

   }
}
-(void)CommonScanResult:(NSString *)codeStr
{
    //NSLog(@"codeStr=====%@",codeStr);
    if (commonScanVC.view!=nil) {
        //   NSLog(@"dddddddd");
        [commonScanVC removeFromParentViewController];
        [commonScanVC.view removeFromSuperview];
        
    }
    [self requestInventoryInput:codeStr];
    
}


-(void)requestInventoryInput:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
         [params setObject:guideCodeStr forKey:@"GuideCode"];
         [params setObject:styleCodeStr forKey:@"ITypeCode"];
         [params setObject:wareHouseCodeStr forKey:@"WhsCode"];
         [params setObject:codeStr forKey:@"ItemCode"];
         [params setObject:continueItemCodeStr forKey:@"DocNum"];
       // NSLog(@"rrr=%@",params);
        [HttpRequest requestData:@"StoreManager/AddCheckVouch" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    //NSLog(@"rrrrrr===%@",severDataDict.dataDict);
                   // NSMutableArray *mGuidesArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                   // for (int i=0; i<mGuidesArray.count; i++) {
                      [inventoryInputPriceArray insertObject:[severDataDict.dataDict objectForKey:@"Price"] atIndex:0];
                      [inventoryInputProductNameArray insertObject:[severDataDict.dataDict objectForKey:@"ItemName"] atIndex:0];
                      [inventoryInputUrlArray insertObject:[severDataDict.dataDict objectForKey:@"ImageUrl"] atIndex:0];
                      [inventoryInputWeightArray insertObject:[severDataDict.dataDict objectForKey:@"Gram"] atIndex:0];
                      [inventoryInputCodeArray insertObject:[severDataDict.dataDict objectForKey:@"ItemCode"] atIndex:0];
                      [inventoryInputAddressArray  insertObject:[severDataDict.dataDict objectForKey:@"WhsName"]atIndex:0];
                  //  }
                    // NSLog(@"guideCodeArray==%@",guideCodeArray);
                    //
                    [_inventoryInputTableView reloadData];
                    float total=0.0f;
                    for (int i=0;i<inventoryInputWeightArray.count; i++) {
                        total=total+[[inventoryInputWeightArray objectAtIndex:i] floatValue];
                    }
                    _inventoryInputTotalLabel.text=[NSString stringWithFormat:@"(共%lu件，%0.02fg)",(unsigned long)inventoryInputWeightArray.count,total];
                   // oldMeterialTotalAmountFloat=total;
//                    _productPageIndex=0;
//                    [self loadProductNextPage:_productPageIndex];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                      //  [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_refreshHeaderView == nil) {
        
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _inventoryListTablebView.bounds.size.height, self.view.frame.size.width, _inventoryListTablebView.bounds.size.height)];
        view.delegate = self;
        [_inventoryListTablebView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [inventoryNumArray removeAllObjects];
    [inventoryProductNameArray removeAllObjects];
    [inventoryGuideNameArray removeAllObjects];
    [inventoryDateArray removeAllObjects];
    [inventoryStatusArray removeAllObjects];
    [inventoryPriceArray removeAllObjects];
    [inventoryNumberArray removeAllObjects];
    [inventoryWeightArray removeAllObjects];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_inventoryListTablebView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
      if (scrollView==_inventoryListTablebView) {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
      }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
      if (scrollView==_inventoryListTablebView) {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
      }
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //    NSMutableArray *codeArrays = [NSMutableArray arrayWithArray:[shopCartData objectForKey:@"PRODUCTCODE"]];
    //    return [codeArrays count];
    if (tableView ==_inventoryListTablebView) {
        return inventoryNumArray.count;
    }
    else if(tableView==_guideListTableView)
    {
        return guideCodeArray.count;
    }
    else if(tableView==_styleListTableView)
    {
        return styleCodeArray.count;
    }
    else if(tableView==_wareHouseListTableView)
    {
        return wareHouseCodeArray.count;
    }
    else if(tableView==_inventoryInputTableView)
    {
        return inventoryInputUrlArray.count;
    }
    else if(tableView==_detailTableView)
    {
        return detailCodeArray.count;
    }
   
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==_inventoryListTablebView||tableView==_inventoryInputTableView||tableView==_detailTableView)
        return 120.0f;
    return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_inventoryListTablebView) {
        static NSString * identifier = @"Cell";
        InventoryManageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"InventoryManageTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            cell.delegate=self;
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.reportConfirmBtn.tag=indexPath.row;
        if (inventoryNumArray.count>0) {
            cell.numLabel.text=[NSString stringWithFormat:@"%@",[inventoryNumArray objectAtIndex:indexPath.row]];
     
        }
        if (inventoryStatusArray.count>0) {
            NSString *statusStr=[NSString stringWithFormat:@"%@",[inventoryStatusArray objectAtIndex:indexPath.row] ];
            
            cell.statusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
            [cell.statusLabel setBackgroundColor:[UIColor clearColor]];
            if ([statusStr isEqualToString:@"未确定"]) {
              //  NSLog(@"statusStr===%@",statusStr);
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                
            }
            
//            if ([statusStr isEqualToString:@"部分到货"]) {
//                [cell.statusLabel setBackgroundColor:[UIColor colorWithRed:199.0f/255.0f green:156.0f/255.0f blue:43.0f/255.0f alpha:1.0f]];
//            }
            else {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
            }
        }
        
        
        if (inventoryPriceArray.count>0) {
            float AvgPrice=[[inventoryPriceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            //  NSString *marketStr=[NSString stringWithFormat:@"¥%0.02f",[[inquiryPriceArray objectAtIndex:indexPath.row] floatValue]];
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];

           // cell.priceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[inventoryPriceArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (inventoryDateArray.count>0) {
            cell.dateLabel.text=[inventoryDateArray objectAtIndex:indexPath.row];
        }
        if (inventoryGuideNameArray.count>0) {
            NSString *guideNameStr=[inventoryGuideNameArray objectAtIndex:indexPath.row];
            if (guideNameStr.length>0) {
                cell.guideNameLabel.text=guideNameStr;
            }
            else
            {
                cell.guideNameLabel.text=@"未填写";
            }
            
        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (inventoryNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[inventoryNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (inventoryWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%@",[Global floatConvertPercentile:[[inventoryWeightArray objectAtIndex:indexPath.row] floatValue]]];
        }

        if (inventoryProductNameArray.count>0) {
           nameStr=[NSString stringWithFormat:@"%@",[inventoryProductNameArray objectAtIndex:indexPath.row]];
            if ([numberStr floatValue]>1) {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
                cell.productNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }
           }
        
        
        if (indexPath.row == [inventoryNumArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                   // NSLog(@"indexPath.row");
                [self loadProductNextPage:_productPageIndex];
            }
            
        }
        return cell;
    }
    else if(tableView==_guideListTableView)
    {
        static NSString * const  GuideListIdentifier = @"GuideListCellIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: GuideListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
  
    else if(tableView==_styleListTableView)
    {
        static NSString * const  StyleListIdentifier = @"StyleListIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: StyleListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (styleNameArray.count>0) {
            cell.guideNameLabel.text=[styleNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if(tableView==_wareHouseListTableView)
    {
        static NSString * const  StyleListIdentifier = @"StyleListIdentifier";
        GuideListTableViewCell *cell=( GuideListTableViewCell *)[tableView dequeueReusableCellWithIdentifier: StyleListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"GuideListTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (wareHouseNameArray.count>0) {
            cell.guideNameLabel.text=[wareHouseNameArray objectAtIndex:indexPath.row];
        }
        return cell;
        
    }
    else if(tableView==_inventoryInputTableView)
    {
        static NSString * const  InventoryInputIdentifier = @"InventoryInputIdentifier";
        InventoryInputTableViewCell *cell=( InventoryInputTableViewCell *)[tableView dequeueReusableCellWithIdentifier: InventoryInputIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"InventoryInputTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (inventoryInputUrlArray.count>0) {
            if ([[inventoryInputUrlArray objectAtIndex:indexPath.row] length]>0) {
           
            [cell.productImageView setImageWithURL:[NSURL URLWithString:[inventoryInputUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
             [cell.productImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (inventoryInputProductNameArray.count>0) {
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@ %@",[inventoryInputCodeArray objectAtIndex:indexPath.row],[inventoryInputProductNameArray objectAtIndex:indexPath.row]];//[inventoryInputProductNameArray objectAtIndex:indexPath.row];
        }
        if (inventoryInputPriceArray.count>0) {
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[inventoryInputPriceArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (inventoryInputWeightArray.count>0) {
            cell.weightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[inventoryInputWeightArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (inventoryInputAddressArray.count>0) {
            cell.stockAddressLabel.text=[inventoryInputAddressArray objectAtIndex:indexPath.row];
        }

        return cell;
        
    }
    else if(tableView==_detailTableView)
    {
        static NSString * const  detailTableViewIdentifier = @"detailTableViewIdentifier";
        InventoryDetailTableViewCell *cell=( InventoryDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: detailTableViewIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"InventoryDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.receiverLabel.hidden=NO;
        cell.receiverTagLabel.hidden=NO;
        if (detailUrlArray.count>0) {
            if ([[detailUrlArray objectAtIndex:indexPath.row] length]>0) {
                
            [cell.resultProductImageView setImageWithURL:[NSURL URLWithString:[detailUrlArray objectAtIndex:indexPath.row]]];
            }
            else
            {
            [cell.resultProductImageView setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
            }
        }
        if (detailProductNameArray.count>0) {
            cell.resultProductNameLabel.text=[NSString stringWithFormat:@"%@ %@",[detailCodeArray objectAtIndex:indexPath.row],[detailProductNameArray objectAtIndex:indexPath.row]];
        }
        if (detailAddressArray.count>0) {
            cell.storeAddressLabel.text=[detailAddressArray objectAtIndex:indexPath.row];
        }
        if (detailAttributesArray.count>0) {
            if ([detailAttributesArray objectAtIndex:indexPath.row]!=[NSNull null]) {
                cell.attributesLabel.text=[NSString stringWithFormat:@"%@",[detailAttributesArray objectAtIndex:indexPath.row]];
                
            }
           // [self resizeLabel: cell.attributesLabel];
             [Global resizeForLable: cell.attributesLabel WithText: cell.attributesLabel.text parentView:self.view];
            CGRect frame= cell.weightTagLabel.frame;
            if ([[detailAttributesArray objectAtIndex:indexPath.row] length]>0) {
                
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width+12;
            }
            else
            {
                frame.origin.x=cell.attributesLabel.frame.origin.x+cell.attributesLabel.frame.size.width;
            }
            cell.weightTagLabel.frame=frame;
            
            CGRect frame1= cell.resultProductWeightLabel.frame;
            frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+1;
            cell.resultProductWeightLabel.frame=frame1;
            
        }

        if (detailWeightArray.count>0) {
            cell.resultProductWeightLabel.text=[NSString stringWithFormat:@"%0.02fg",[[detailWeightArray objectAtIndex:indexPath.row] floatValue]];
           // [self resizeLabel:cell.resultProductWeightLabel];
             [Global resizeForLable: cell.resultProductWeightLabel WithText: cell.resultProductWeightLabel.text parentView:self.view];
        }
        if (detailGuideNameArray.count>0) {
            cell.receiverLabel.text=[detailGuideNameArray objectAtIndex:indexPath.row];
            //[self resizeLabel:cell.resultProductWeightLabel];
        }

        if (detailPriceArray.count>0) {
            cell.resultProductPriceLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[detailPriceArray objectAtIndex:indexPath.row] floatValue]];
            CGRect frame1= cell.resultProductPriceLabel.frame;
            frame1.origin.x=cell.resultProductWeightLabel.frame.origin.x+cell.resultProductWeightLabel.frame.size.width+20;
            cell.resultProductPriceLabel.frame=frame1;

        }

        cell.dotLineLabel.hidden=NO;
        cell.lineLabel.hidden=YES;
        if (indexPath.row == [detailCodeArray count] - 1)
        {
            cell.dotLineLabel.hidden=YES;
            cell.lineLabel.hidden=NO;
            if (_detailPageIndex<=_detailTotalPage) {
                 //   NSLog(@"##=====%d",indexPath.row);
               //  NSLog(@"###=====%d",indexPath.row);
                [self loadDetailNextPage:_detailPageIndex];
            }
            
        }

        return cell;
        
    }


    return nil;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_detailTableView && [inventoryTypeStr isEqualToString: @"I" ]) {
        return YES;
    }
    return NO;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView==_detailTableView && [inventoryTypeStr isEqualToString: @"I" ])
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            if ([Global getLoginToken].length>0) {
                [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
                NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
                
                [params setObject:[Global getLoginToken] forKey:@"Token"];
                [params setObject:_detailNumLabel.text forKey:@"DocNum"];
                 NSMutableArray *dataLineArray=[NSMutableArray array];
                 NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                 [dic setValue:[detailCodeArray objectAtIndex:indexPath.row] forKey:@"ItemCode"];
                 [dataLineArray addObject:dic];
                [params setObject:dataLineArray forKey:@"DataLine"];
                
               // NSLog(@"params====%@",params);
                [HttpRequest requestData:@"StoreManager/DelCheckVouch" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                    if (isSuccess) {
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                            [Global hideProgressHUDInternal:self.view];
                            [detailUrlArray removeObjectAtIndex:indexPath.row];
                            [detailProductNameArray removeObjectAtIndex:indexPath.row];
                            [detailPriceArray  removeObjectAtIndex:indexPath.row];
                            [detailCodeArray removeObjectAtIndex:indexPath.row];
                            [detailWeightArray removeObjectAtIndex:indexPath.row];
                            [detailGuideNameArray removeObjectAtIndex:indexPath.row];
                            [detailAttributesArray removeObjectAtIndex:indexPath.row];
                            [detailAddressArray removeObjectAtIndex:indexPath.row];
                            [_detailTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                            [tableView reloadData];
                            
//                            NSString *nQtyStr=[NSString stringWithFormat:@"%ld",(long)[IQtyStr integerValue]-1];
//                            NSString *panCunStr=[NSString stringWithFormat:@"盘存%ld件",(long)[ nQtyStr integerValue]];
//                            [_panCunTitle setText:panCunStr];
                            [self requestDetailHead];
                            
                        }
                        else
                        {
                            [Global hideProgressHUDInternal:self.view];
                            NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                            //  [Global showTextHud:requestResultStr view:self.view];
                            [Global showTextHudSub:requestResultStr view:self.view];
                            
                            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                            [Global loginViewController:self noteStr:requestResultStr];
                                //   [Global loginViewController:self];
                            }
                        }
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        [Global showTextHudSub:@"连接失败" view:self.view];
                    }
                }];
                
            }
        }
    }
    
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_guideListTableView) {
        guideCodeStr=[guideCodeArray objectAtIndex:indexPath.row];
        
        _guideListViewContainer.hidden=YES;
        [UIView animateWithDuration:0.5 animations:^{
            
            UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            [_selectGuideArrow setImage:closeImage];
            CGRect frame=_guideListViewContainer.frame;
            
            frame.size.height=1;
            [_guideListViewContainer setFrame:frame];
            
        } completion:^(BOOL finished){
            guideIsOpen=NO;
        }];
        _selectGuideLabel.text=[guideNameArray objectAtIndex:indexPath.row];
        [Global resizeForLable:_selectGuideLabel WithText:_selectGuideLabel.text parentView:self.view];
        CGRect frameK=_selectGuideLabel.frame;
        frameK.origin.x=_selectGuideArrow.frame.origin.x-frameK.size.width-5;
        _selectGuideLabel.frame=frameK;
    }
    else if (tableView==_detailTableView)
    {
        _isLoad=@"Y";
        if (commonProductDetailVC.view!=nil) {
            
            [commonProductDetailVC removeFromParentViewController];
            [commonProductDetailVC.view removeFromSuperview];
            
        }
        commonProductDetailVC=[[CommonProductDetailViewController alloc] init];
        commonProductDetailVC.delegate=self;
        commonProductDetailVC.codeStr=[detailCodeArray objectAtIndex:indexPath.row];
        commonProductDetailVC.view.frame = CGRectMake(0,
                                                      0,
                                                      self.view.bounds.size.width,
                                                      self.view.bounds.size.height);
        
        [self addChildViewController:commonProductDetailVC];
        [self.view addSubview:commonProductDetailVC.view];
    }
    else if (tableView==_styleListTableView) {
      
       UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
       [_selectStyleArrow setImage:closeImage];
        styleCodeStr=[styleCodeArray objectAtIndex:indexPath.row];
        
        _styleListView.hidden=YES;
       
        [UIView animateWithDuration:0.5 animations:^{
            
            // UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
            //  [_selectGuideArrowImageView setImage:closeImage];
            CGRect frame=_styleListView.frame;
            
            frame.size.height=1;
            [_styleListView setFrame:frame];
            
        } completion:^(BOOL finished){
             styleIsOpen=NO;
        }];
        _selectStyleLabel.text=[styleNameArray objectAtIndex:indexPath.row];
        [Global resizeForLable:_selectStyleLabel WithText:_selectStyleLabel.text parentView:self.view];
        CGRect frames=_selectStyleLabel.frame;
        frames.origin.x=_selectStyleArrow.frame.origin.x-frames.size.width-5;
        _selectStyleLabel.frame=frames;
        [self  requestInventoryNum];
    }
   else if (tableView==_wareHouseListTableView) {
      
       wareHouseCodeStr=[wareHouseCodeArray objectAtIndex:indexPath.row];
       
       _wareHouseListView.hidden=YES;
       UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
       [_selectWareHouseArrow setImage:closeImage];
       
       [UIView animateWithDuration:0.5 animations:^{
           
           // UIImage *closeImage=[UIImage imageNamed:@"jiantou_down.png"];
           //  [_selectGuideArrowImageView setImage:closeImage];
           CGRect frame=_wareHouseListView.frame;
           
           frame.size.height=1;
           [_wareHouseListView setFrame:frame];
           
       } completion:^(BOOL finished){
           wareHouseIsOpen=NO;
       }];
     //  NSArray *array=[NSArray arrayWithObjects:@"广东省东莞市明峰店会讲", @"会讲点",nil];
       _selectWareHouseLabel.text=[wareHouseNameArray objectAtIndex:indexPath.row];
        [self  requestInventoryNum];
       [Global resizeForLable:_selectWareHouseLabel WithText:_selectWareHouseLabel.text parentView:self.view];
       CGRect frameK=_selectWareHouseLabel.frame;
       frameK.origin.x=_selectWareHouseArrow.frame.origin.x-frameK.size.width-5;
       _selectWareHouseLabel.frame=frameK;
   }
else if (tableView==_inventoryListTablebView)
{
   // NSLog(@"11");
    [_searchTextField resignFirstResponder];
    inventoryCellTag=indexPath.row;
    [detailUrlArray removeAllObjects];
    [detailProductNameArray removeAllObjects];
    [detailAddressArray removeAllObjects];
    [detailWeightArray removeAllObjects];
    [detailGuideNameArray removeAllObjects ];
    [detailAttributesArray removeAllObjects];
    [detailPriceArray removeAllObjects];
    [detailCodeArray removeAllObjects];
   // [detailCodeArray removeAllObjects];
    inventoryNumStr=[inventoryNumArray objectAtIndex:indexPath.row];
    inventoryTypeStr=@"Y";
    _panCunLine.hidden=YES;
    _panKuiLine.hidden=YES;
    _panYinLine.hidden=NO;
    [_inventoryConfirmBtn setBackgroundColor:[UIColor colorWithRed:199.0f/255.0f green:156.0f/255.0f blue:44.0f/255.0f alpha:1.0f]];
    [_inventoryConfirmBtn setUserInteractionEnabled:YES];
    

    [self requestDetailHead];
    _detailPageIndex=0;
    [self loadDetailNextPage:_detailPageIndex];
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_detailViewContainer.frame;
         viewFrame.origin.y=0;
         _detailViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
}
-(void)commonProductDetailShopCartClick
{
    if ([self.delegate respondsToSelector:@selector(InventoryManageShopCtarClick)]) {
        
        [self.delegate InventoryManageShopCtarClick];
    }
    
}

//- (void)textClick
//{
//    
//    [_inputSearchTextField
//     becomeFirstResponder];
//}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField==_searchProductTextField)
    {
        if (guideCodeStr.length>0&&styleCodeStr.length>0&&wareHouseCodeStr.length>0) {
               return YES;

        }
        
        else
        {
           
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择导购、类别、仓库" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
             return NO;
            
            
        }

        
    }
    return YES;
}
-(void)requestInventoryNum
{
    if (styleCodeStr.length>0&&wareHouseCodeStr.length>0) {
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            [params setObject:styleCodeStr forKey:@"ITypeCode"];
            [params setObject:wareHouseCodeStr forKey:@"WhsCode"];
            [params setObject:_detailNumLabel.text forKey:@"WhsCode"];
          //  NSLog(@"pprrrr===%@",params);
            [HttpRequest requestData:@"StoreManager/GetCheckVouchMsg" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        _inventoryNumLabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                        if (_inventoryNumLabel.text.length>0) {
                            _inventoryInputNoteView.hidden=NO;
                            CGRect frameQ=_inventoryInputInfoView.frame;
                            frameQ.origin.y=_inventoryInputNoteView.frame.origin.y+_inventoryInputNoteView.frame.size.height+1;
                            _inventoryInputInfoView.frame=frameQ;
                            
                            
                        }
                        else
                        {
                           _inventoryInputNoteView.hidden=YES;
                            
                            CGRect frameQ=_inventoryInputInfoView.frame;
                            frameQ.origin.y=_inputReferLineLabel.frame.origin.y+_inputReferLineLabel.frame.size.height+1;
                            _inventoryInputInfoView.frame=frameQ;
                            
                            
                        }
                        CGRect frameW=_inventoryInputTableView.frame;
                        frameW.origin.y=_inventoryInputInfoView.frame.origin.y+_inventoryInputInfoView.frame.size.height+1;
                        _inventoryInputTableView.frame=frameW;
                        }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                                [Global loginViewController:self noteStr:requestResultStr];
                            //[Global loginViewController:self];
                        }
                        
                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
            }];
            
        }

    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField==_searchTextField) {
        [inventoryNumArray removeAllObjects];
        [inventoryProductNameArray removeAllObjects];
        [inventoryGuideNameArray removeAllObjects];
        [inventoryDateArray removeAllObjects];
        [inventoryStatusArray removeAllObjects];
        [inventoryWeightArray removeAllObjects];
        [inventoryNumberArray removeAllObjects];
        [inventoryPriceArray removeAllObjects];
        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchTextField resignFirstResponder];
    }
    else if (textField==_searchProductTextField)
    {
        [self findProductList:_searchProductTextField.text];
        _searchProductTextField.text=@"";
        //[_searchProductTextField resignFirstResponder];
    }
       return YES;
    
}
-(void)findProductList:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"KeyWord"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:1];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:1];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:@"CheckVouch" forKey:@"BType"];
       //  NSLog(@"eeeeee===%@",params);
        [HttpRequest requestData:@"Product/GetPItemList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                 
//                    stringValue=_searchProductTextField.text;
                    [self requestInventoryInput:codeStr];
                    }
                
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        
                        [Global loginViewController:self noteStr:requestResultStr];
                        //[Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

-(void)reportConfirmClick:(NSUInteger)tag
{
    
}
@end
